// 1. 引入 axios
import axios, { AxiosInstance } from "axios";
import headsObj from "../utils/header";

// 2. 创建 实例

const request: AxiosInstance = axios.create({
  baseURL: "https://m.maizuo.com",
  timeout: 300000,
});

// baseURL: import.meta.env.VITE_BASE_URL,
//请求 拦截器

request.interceptors.request.use(
  (config) => config,
  (err) => err
);

// 响应 拦截器

request.interceptors.response.use(
  (config) => config,
  (err) => err
);

// 定义params接口类型
export interface IParams {
  cityId?: number | string;
  pageNum?: number | string;
  pageSize?: number | string;
  type?: number | string;
  k: number | string;
  ticketFlag?: number | string;
  filmId?: number | string;
  cinemaId?: number | string;
}

// 定义key接口类型
type IKeys =
  | "hot"
  | "comeSooning"
  | "cinameList"
  | "movieDetail"
  | "cinameDatail"
  | "cityList";

// 通用请求头
export default function requestApi(params: IParams, key: IKeys) {
  return request.get("/gateway", {
    params: params,
    headers: headsObj[key],
  });
}
